package cn.neusoft.yp.shiro;


import cn.neusoft.yp.tool.MD5Hash;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

//表示密码校验
public class AuthCredential extends  SimpleCredentialsMatcher{
	
	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
		//将用户输入的明文转化为密文
		UsernamePasswordToken loginToken=(UsernamePasswordToken) token;
		String username=loginToken.getUsername();
		char[] password=loginToken.getPassword();
		String md5HashPassword= MD5Hash.getMd5Password(username, String.valueOf(password));
		
		loginToken.setPassword(md5HashPassword.toCharArray());
		
		//将数据传入安全管理器
		return super.doCredentialsMatch(token, info);
	}
}
